package com.jack.leetcode.eachproblem_2020;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by zhang_j on 2020/11/9
 */
public class 最接近原点的K个点 {

    public int[][] kClosest(int[][] points, int K) {
        int[][] result = new int[K][2];

        List<int[]> list = Arrays.asList(points);
        List<int[]> collect = list.stream().sorted(Comparator.comparing(a -> a[0] * a[0] + a[1] * a[1])).collect(Collectors.toList());
        for(int i = 0;i < K;i++){
            result[i] = collect.get(i);
        }
        return result;
    }
}
